<?php
App::uses('AppModel', 'Model');
/**
 * Usuario Model
 *
 * @property GrauDeEnsino $GrauDeEnsino
 * @property Curso $Curso
 * @property Periodo $Periodo
 * @property Bolsa $Bolsa
 * @property Inscricao $Inscricao
 * @property LinguaUsuario $LinguaUsuario
 */
class Usuario extends AppModel {

/**
 * Use table
 *
 * @var mixed False or table name
 */
	public $useTable = 'usuario';

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'nome';


	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'GrauDeEnsino' => array(
			'className' => 'GrauDeEnsino',
			'foreignKey' => 'grau_de_ensino_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Curso' => array(
			'className' => 'Curso',
			'foreignKey' => 'curso_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Periodo' => array(
			'className' => 'Periodo',
			'foreignKey' => 'periodo_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'Bolsa' => array(
			'className' => 'Bolsa',
			'foreignKey' => 'usuario_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Inscricao' => array(
			'className' => 'Inscricao',
			'foreignKey' => 'usuario_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'LinguaUsuario' => array(
			'className' => 'LinguaUsuario',
			'foreignKey' => 'usuario_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
        
        function beforeSave($data){
		/* caso a ação seja adicionar, aplica a criptografia a senha */
                if(!empty($this->data['Usuario']['password'])){
                        $this->data['Usuario']['password'] = AuthComponent::password($this->data['Usuario']['password']);
                }
	}

}
